package com.syerit.modules.worldgreen3d.view
{
	import com.syerit.modules.worldgreen3d.model.ModuleModelLocator;
	
	import flash.events.Event;
	
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.parsers.Collada;
	import org.papervision3d.view.BasicView;
	
	public class Scene3D extends BasicView
	{
		private var appModel:ModuleModelLocator = ModuleModelLocator.getInstance();
		private var land:Collada;
		
		public function Scene3D(viewportWidth:Number=640, viewportHeight:Number=480, scaleToStage:Boolean=false, interactive:Boolean=true, cameraType:String="Debug")
		{
			super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
			init();
		}
		private function init():void
		{
			//scene.addChild(new Plane(new ColorMaterial(),200,200,4,4));
			var matList:MaterialsList = new MaterialsList();
			matList.addMaterial(new BitmapMaterial(appModel.loadedDataModel.images.concrete.bitmapData),"_4_-_Default");
			matList.addMaterial(new ColorMaterial(0xFFCC22),"_2_-_Default");
			matList.addMaterial(new ColorMaterial(0x0055FF),"_6_-_Default");
			land = new Collada(appModel.settingsModel.prefix+"meshes/road.dae",matList);
			
		}
		public function activate():void
		{
			scene.addChild(land);
			addEventListener(Event.ENTER_FRAME,update);
		}
		public function deactivate():void
		{
			trace(land.materialsToLoad);
			
			scene.removeChild(land);
			this.stopRendering();
			removeEventListener(Event.ENTER_FRAME,update);
			//land = null;
		}
		public function update(e:Event):void
		{
			this.singleRender();
			trace("aaaa");
		}
		
	}
}